class UsersSurveysPermission < ActiveRecord::Base
	include AliasingColumns
        
        set_table_name "USERS_SURVEYS_PERMISSIONS"
	AliasingColumns.add_aliases columns
		
		belongs_to :user,
			   :class_name => "User",
			   :foreign_key => "user_id"
		belongs_to :survey,
			   :class_name => "Survey",
			   :foreign_key => "survey_id"
		belongs_to :permissiontype,
			   :class_name => "SurveyPermissionType",
			   :foreign_key => "permission_type_id"
	
			   
	def self.not_temp
		temp_id=SystemRole.find_by_name("TempSurveyee").id;
		UsersSurveysPermission.find(:all,:joins=>"JOIN USERS u ON USERS_SURVEYS_PERMISSIONS.user_id=u.id",
		:conditions=>"u.role_id!=#{temp_id}")
		
	end	   
	if  AliasingColumns.get_adapter_name == "oracle"
#		self.primary_key ="ID"	
		set_sequence_name table_name()<<"_SEQ" 
#		before_create :set_id
		def set_id
			 self.ID =connection.next_sequence_value(self.class.sequence_name)	
		end 
	end
				   
			   
end
